<template>
  <view class="page u-padding-20">

    <u-empty text="地址列表" mode="page" v-if="addressList.length === 0"></u-empty>

    <view v-for="(res, index) in addressList" :key="res.addr_id" class="base-panel-box u-m-b-20">
	<view >
      <view class="htitle">
        {{res.region_fullname}}
		<text class="u-p-l-20" v-if="res.is_default">[{{$t('default')}}]</text>
        <view class="right">
			<u-icon name="edit-pen" class=" u-p-t-12" color="#999999" size="26" @click="toAddSite('edit', res.addr_id)" >{{$t('modify')}}</u-icon>
			
		</view>
      </view>
      <view class="item" @click="checkAddress(res)">
			<view > {{ res.consignee }} {{ res.mobile }} </view>
			<view>{{ res.address }}</view>
      </view>
	  </view>
    </view>

    <view class="addSite u-m-t-50" @tap="toAddSite('add','')">
      <view class="add">
        <u-icon name="plus" color="#ffffff" class="icon" :size="15"></u-icon>{{$t('new')}}
      </view>
    </view>
	<u-gap height="200"></u-gap>
  </view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex';
	import { api_user_addresslist } from '@/config/api.js';
export default {
  data() {
    return {
	  loadstatus:false,
      addressList: [],
      source: 0,
    };
  },
  onLoad(option) {
    this.source = option.source;
	uni.setNavigationBarTitle({title: this.$t('pagetitle.address')});
  },
  onShow() {
    this.refreshList();
  },
	computed:{
	    ...mapState(['userInfo']),
		},
  methods: {
    //添加或修改成功之后回调
    refreshList(data, type) {
		api_user_addresslist({
			find_users_id:this.userInfo.member_id
		}).then((res) => {
			console.log(res)
			this.addressList = Array.isArray(res.roomlist) ? res.roomlist : [];
		}).catch((err) =>{})

    },
    toAddSite(type, id) {
      uni.navigateTo({
          url: '/pagesPackageA/address/edit/edit?type='+type+'&id='+id
      });
    },
    checkAddress(item) {
      if (this.source == 1) {
        let pages = getCurrentPages();
        let prePage = pages[pages.length - 2];
        // #ifdef H5
        prePage.addressData = item;
        // #endif
        prePage.$vm.addressData = item;
        uni.navigateBack(1);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.item {
  padding: 20rpx 20rpx;
  .top {
    display: flex;
    font-weight: bold;
    font-size: 34rpx;
  }
  .bottom {
    display: flex;
    margin-top: 20rpx;
    font-size: 28rpx;
    justify-content: space-between;
    color: #999999;
  }
}
.addSite {
  display: flex;
  justify-content: space-around;
  width: 600rpx;
  line-height: 100rpx;
  margin: auto;
  bottom: 120rpx;
  left: 80rpx;
  background-color: red;
  border-radius: 60rpx;
  font-size: 30rpx;
  .add {
    display: flex;
    align-items: center;
    color: #ffffff;
    .icon {
      margin-right: 10rpx;
    }
  }
}
</style>
